/**
 * Friendly Interactive Recursion Educator (FIRE)
 * COMS 4115: Programming Languages & Translators
 * Prof. Aho
 * 
 * @author Brian Lu
 * @author Sahar Hasan
 * @author Steve Hehl
 * @author Tristan Naumann
 * @version 2009-05-12
 */
package fire;

/**
 * Basic symbol class which stores a name and type.  To be inherited by
 * other type checking symbols.
 */
public class Symbol{

    public String name;
    public Symbol type;

    public Symbol(String name) {
        this.name = name;
    }

    public Symbol(String name, Symbol type) {
        this.name = name;
        this.type = type;
    }
    
    /**
     * Recursively defined type equivalence. Since a VariableSymbol/List
     * might have nested types.
     * @param other the other Symbol
     * @return whether this symbol is of the same type as other.
     */
    public boolean sameType (Symbol other) {
    	if ((type == null && other.type != null)
    			|| (other.type == null && type != null))
    		return false;	// type mismatch
    	if (type == null && other.type == null)
    		return name == other.name;
    	return type.sameType(other.type);
    }
}
